package com.gzc.pm.logic
{
	import cn.skyclass.net.BaseSubmitter;
	import cn.skyclass.net.OperationResult;
	
	import com.gzc.pm.bean.CPLRouteBean;
	import com.gzc.pm.dao.CplRouteDao;
	
	import mx.rpc.events.ResultEvent;
	
	public class CplRouteEditor extends BaseSubmitter
	{
		public function CplRouteEditor(route:CPLRouteBean, editMode:Boolean = false)
		{
			_route = route;
			_editMode = editMode;
		}
		
		private var _route:CPLRouteBean;
		private var _editMode:Boolean;
		
		override protected function doSubmit():void{
			var cplRouteDao:CplRouteDao = new CplRouteDao();
			if(_editMode){
				cplRouteDao.update(_route, onUpdated);
			}else{
				cplRouteDao.insert(_route, onAdded);
			}
		}
		
		private function onAdded(e:ResultEvent):void{
			var result:OperationResult = e.result as OperationResult;
			_route.id = result.id;
			
			dispatchSubmittedEvent();
		}
		
		private function onUpdated(e:ResultEvent):void{
			var result:OperationResult = e.result as OperationResult;
			
			dispatchSubmittedEvent();
		}
		
	}
}